import { Module } from "@nestjs/common";
import { JwtModule } from "@nestjs/jwt";
import { PassportModule } from "@nestjs/passport";
import { UserModule } from "../user/user.module";
import { AuthController } from "./auth.controller";
import { AuthService } from "./auth.service";
import { jwtConstants } from "./constants";
import { JwtStrategy } from "src/utils/strategies/jwt.strategy";
import { LocalStrategy } from "src/utils/strategies/local.strategy";
import { APP_GUARD } from "@nestjs/core";
import { JwtAuthGuard } from "src/utils/guards/jwt-auth.guard";
import { CompanyModule } from "src/modules/company/company.module";

@Module({
  imports: [
    UserModule,
    PassportModule,
    CompanyModule,
    JwtModule.register({
      secret: jwtConstants.secret,
      signOptions: { expiresIn: "7d" },
    }),
  ],
  // 注册服务 Auth，LocalStrategy, JwtStrategy
  providers: [
    AuthService,
    LocalStrategy,
    JwtStrategy,
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
  ],
  controllers: [AuthController],
  // 向外导出 AuthService
  exports: [AuthService],
})
export class AuthModule {}
